#include "bo3d.h"

// Creates a camera to be managed by this scene manager. 
BBDECL Ogre::Camera* __stdcall o_createCamera(Ogre::SceneManager* scm, const char* name)
{
	Ogre::Camera* cam;

	try
	{
		cam = scm->createCamera(Ogre::String(name));
	}
	catch(Ogre::Exception &e)
	{
		std::cout << e.getDescription() << std::endl;
	}

	return cam;
}

// Sets the camera's position. 
BBDECL void __stdcall o_camera_setPosition(Ogre::Camera* cam, float x, float y, float z)
{
	cam->setPosition(Ogre::Real(x), Ogre::Real(y), Ogre::Real(z));
}

// Sets the aspect ratio for the frustum viewport. 
BBDECL void __stdcall o_setAspectRatio(Ogre::Camera* cam, float ratio)
{
	try
	{
		cam->setAspectRatio(Ogre::Real(ratio));
	}
	catch(Ogre::Exception &e)
	{
		std::cout << e.getDescription() << std::endl;
	}
}

// Moves the camera's position by the vector offset provided along it's own axes (relative to orientation). 
BBDECL void __stdcall o_camera_moveRelative(Ogre::Camera* cam, boVec3* vec)
{
	try
	{
		cam->moveRelative(Ogre::Vector3(Real(vec->x), Real(vec->y), Real(vec->z)));
	}
	catch(Ogre::Exception &e)
	{
		std::cout << e.getDescription() << std::endl;
	}
}

// Sets the position of the near clipping plane. 
BBDECL void __stdcall o_setNearClipDistance(Ogre::Camera* cam, float nearClipDistance)
{
	try
	{
		cam->setNearClipDistance(Ogre::Real(nearClipDistance));
	}
	catch(Ogre::Exception &e)
	{
		std::cout << e.getDescription() << std::endl;
	}
}

// Sets the position of the far clipping plane. 
BBDECL void __stdcall o_setFarClipDistance(Ogre::Camera* cam, float farClipDistance)
{
	try
	{
		cam->setFarClipDistance(Ogre::Real(farClipDistance));
	}
	catch(Ogre::Exception &e)
	{
		std::cout << e.getDescription() << std::endl;
	}
}

// Pitches the camera up/down anticlockwise around it's local x axis. 
BBDECL void __stdcall o_camera_pitch(Ogre::Camera* cam, float pitch)
{
	try
	{
		cam->pitch(Ogre::Radian(pitch));
	}
	catch(Ogre::Exception &e)
	{
		std::cout << e.getDescription() << std::endl;
	}
}

// Rotates the camera anticlockwise around it's local y axis. 
BBDECL void __stdcall o_camera_yaw(Ogre::Camera* cam, float yaw)
{
	try
	{
		cam->yaw(Ogre::Radian(yaw));
	}
	catch(Ogre::Exception &e)
	{
		std::cout << e.getDescription() << std::endl;
	}
}

// Rolls the camera anticlockwise, around its local z axis. 
BBDECL void __stdcall o_camera_roll(Ogre::Camera* cam, float roll)
{
	try
	{
		cam->roll(Ogre::Radian(roll));
	}
	catch(Ogre::Exception &e)
	{
		std::cout << e.getDescription() << std::endl;
	}
}

BBDECL boVec3* __stdcall o_camera_getPosition(Ogre::Camera* cam)
{
	boVec3* vec3 = new boVec3;
	try
	{
		Ogre::Vector3 v = cam->getPosition();
		vec3->x = v.x;
		vec3->y = v.y;
		vec3->z = v.z;
	}
	catch(Ogre::Exception &e)
	{
		std::cout << e.getDescription() << std::endl;
	}

	return vec3;
}

BBDECL Ogre::Viewport* __stdcall o_camera_getViewPort(Ogre::Camera* cam)
{
	Ogre::Viewport* vp;
	try
	{
		vp = cam->getViewport();
	}
	catch(Ogre::Exception &e)
	{
		std::cout << e.getDescription() << std::endl;
	}

	return vp;
}